<template>
  <div class="app-container">
    <!-- 放置表单 -->
    <el-form
      ref="fm"
      label-width="60px"
      :model="userDetail"
      :rules="rules"
    >
      <el-form-item
        label="姓名:"
        prop="username"
      >
        <el-input
          v-model="userDetail.username"
          style="width: 300px"
        />
      </el-form-item>
      <el-form-item label="密码:">
        <el-input
          v-model="userDetail.password"
          style="width: 300px"
          type="password"
          disabled
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          @click="updateUser"
        >更新</el-button>
        <el-button>返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveUserDetailById } from '@/api/employees.js'
export default {
  props: {
    userDetail: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      rules: {
        username: [{ required: true, min: 3, max: 10, message: '用户名必填！', trigger: 'change' }]
      }
    }
  }, methods: {
    async updateUser () {
      try {
        await this.$refs.fm.validate()
        await saveUserDetailById(this.userDetail)
        this.$message.success('更新成功')
        this.$router.back()
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
